#ifndef SEU_LOGGER
#define SEU_LOGGER
#include"include.h"

/*
 * So multiple can be enabled we define them sequentially.
 * This allows them to be an arrays indexes for a bitfield.
 * Other is a log method which allows for a function pointer
 * to be called. This is intended for use as part of the gui
 * The errors can be written to some gui element this way
 * with the gui providing the callback
 */
typedef enum {
   LOG_FILE   = 0,
   LOG_STDOUT = 1,
   LOG_STDERR = 2,
   LOG_OTHER  = 3
} log_type;

/*
 * Sequential so we can ask if log_level <= LOG_ERR. This gives
 * an intuitive way to allow each to imply all the previous ones
 */
typedef enum {
   LOG_NONE = 0,
   LOG_ERR  = 1,
   LOG_WARN = 2,
   LOG_INFO = 3,
   LOG_DEBUG = 4
} log_level;

typedef struct {
   log_type type[LOG_OTHER+1]; //Allow multiple types. Bitfield for enable/disable
   log_level level;
   void *(*other)();
   FILE *file;
} logger_t;

/*
 * This is sort of a singleton in that there will only ever be one logger. We'll
 * declare it here where everything can get at it.
 */

logger_t *logger; //Don't name this log. Stupid Math.h


void loggerInit();


/*
 * Each of the loggerEnable* functions acts as a disable too.
 * Pass in NULL for the second argument to indicate that method
 * should be disabled. eg: loggerEnableFile(logger, NULL); //disables
 */
void loggerEnableFile(FILE *f);
void loggerEnableStdout(short tf);
void loggerEnableStderr(short tf);
void loggerEnableOther(void *other);

void loggerSetLevel(log_level);

//Hey, it's my own printf! But more flexible
void loggerLog(log_level level, char *message, ...)
   __attribute__ ((format(printf,2,3)));

void loggerExit();
#endif
